const {
  $util,
} = getApp();
Page({
  data: {
    nav: [{ // career公益事业 datachecknews资讯 investigate党建考察报告  promisenew党建承诺
      title: '待审批',
      id: 0,
    }, {
      title: '已驳回',
      id: 2,
    }, {
      title: '已通过',
      id: 1,
    }],
    nav1: [{ // offrecord线下培训 multitap关系转接 learnrecord中心组学习记录
      title: '未审核',
      id: 1,
    }, {
      title: '已驳回',
      id: 2,
    }, {
      title: '已通过',
      id: 3,
    }],
    nav2: [{ // upload志愿服务
      title: '未审核',
      id: 1,
    }, {
      title: '已驳回',
      id: 3,
    }, {
      title: '已通过',
      id: 2,
    }],
    nav3: [{ // secretarymail党风廉政书记信箱
      title: '待采纳',
      id: 0,
    }, {
      title: '未采纳',
      id: 2,
    }, {
      title: '已采纳',
      id: 1,
    }],
    nav4: [{ // 关系转接 
      title: '转入',
      id: 0,
    }, {
      title: '转出',
      id: 1,
    }],
    isdo: '', // datachecknews资讯 upload志愿服务 multitap关系转接 learnrecord中心组学习记录 secretarymail党风廉政书记信箱 career公益事业 offrecord线下培训 investigate党建考察报告  promisenew党建承诺
    page: 1,
    list: [],
    check: 0, // 0-未审核，2-已驳回，1-已通过
    hasMore: true,
    sid: 0, // tabbar 默认index
    showtype: 0,   // 关系转接  0-转入 1-转出
    isLoad: false,
    kv: {
      promisenew: '承诺管理', 
      offrecord: '审批培训笔记',
    },
  },
  onLoad(opts) {
    this.setData(opts);
    // if (this.data.kv[opts.isdo]) {
    //   wx.setNavigationBarTitle({
    //     title: this.data.kv[opts.isdo],
    //   });
    // } else 
    if ((opts.isdo === 'secretarymail' || opts.isdo === 'promisenew' || opts.isdo === 'offrecord') && Number(opts.history) === 1) {
      wx.setNavigationBarTitle({
        title: '历史审批',
      });
    } else {
    wx.setNavigationBarTitle({
      title: opts.barTitle && decodeURIComponent(opts.barTitle) || opts.title || '',
    });
    }
  },
  onShow() {
    this.setData({
      page: 1,
    }, () => {
      this.loadList();
    });
    let wxData = wx.getStorageSync('qyUserInfo') || {};
    this.setData(wxData);
    this.setData({
      isSaaS: wx.getStorageSync('isSaaS'),
    });
  },
  changeNav(e) {
    this.setData({
      page: 1,
      sid: e.detail.idx,
      check: e.detail.obj.id,
      hasMore: true,
      isLoad: false,
    }, () => {
      this.loadList();
    });
  },
  changeTransfer(e) {
    this.setData({
      page: 1,
      showtype: e.detail.obj.id,
      hasMore: true,
      isLoad: false,
    }, () => {
      this.loadList();
    });
  },
  loadList() {
    let {
      page,
      check,
      isdo,
      list: lists,
      showtype,
      history,
    } = this.data;
    if (Number(history) === 1) {
      if (isdo === 'offrecord') {
        check = 4;
      } else {
      check = 3;
    }
    }
    
    let param = {
      page,
      check,
    };
    isdo === 'multitap' && (param.showtype = showtype);
    $util.request({
      url: `entry/wxapp/verify.${isdo}.getList`,
      data: param,
      success: (res) => {
        let list = res.list;
        if (page > 1) {
          list = [...lists, ...list];
        }
        this.setData({
          hasMore: res.list.length !== 0,
          page: res.list.length !== 0 ? page + 1 : page,
          list,
          isLoad: true,
        });
      },
    });
  },
  onReachBottom() {
    this.data.hasMore && this.loadList();
  },
});